package com.wust.service.impl;

import com.wust.common.ServerResponse;
import com.wust.dao.FollowMapper;
import com.wust.dao.UserMapper;
import com.wust.entity.Follow;
import com.wust.entity.User;
import com.wust.service.IFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lenovo on 2018/6/14.
 */
@Service("iFollowService")
public class FollowServiceImpl implements IFollowService {

    @Autowired
    private FollowMapper followMapper;

    @Autowired
    private UserMapper userMapper;


    @Override
    public ServerResponse getFollow(int userId, int followId) {
        User user = userMapper.selectByPrimaryKey(followId);
        if(user == null){
            return ServerResponse.createByErrorMessage("用户不存在");
        }
        Follow follow = new Follow();
        follow.setFollowId(followId);
        follow.setFanId(userId);
        int resultCount = followMapper.insertSelective(follow);
        if(resultCount > 0){
            return ServerResponse.createBySuccessMessage("关注成功");
        }
        return ServerResponse.createByErrorMessage("关注失败");
    }

//    public ServerResponse getFollowList(int userId){
//        List<Follow> follows = followMapper.selectByUserId(userId);
//        if(follows.size()==0){
//            return ServerResponse.createByErrorMessage("关注列表为空");
//        }
//
//    }


}
